/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = frstat_ports_add_stat.c                            */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/12 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frexp_comm.h"
#include "frstat_port.h"

extern int frstat_ports_add_stat(u_short proto, u_int ui_dst_ip, u_short us_dst_port
                        , unsigned int ui_tx_bytes, unsigned int ui_rx_bytes
                        , unsigned int ui_tx_pkts, unsigned int ui_rx_pkts);
extern int __conn_key(u_short proto, u_int ui_dst_ip, u_short us_dst_port
                        , char *p_key, unsigned int ui_key_size);

extern void __hash_node_free(Frlist_node *p_st_node);

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

static void case1(void)
{
    int i_ret = 0;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;

    frstat_ports_init(100);

    i_ret = frstat_ports_add_stat(ui_sip, ui_dip, us_dport, 1, 1, 1, 1);
    
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frstat_ports_destroy();
    return;
}

static void case2(void)
{
    int i_ret = 0;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;

    frstat_ports_init(100);
    
    i_ret = frstat_ports_add_stat(ui_sip, ui_dip, us_dport, 1, -1, 1, 1);
    
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frstat_ports_destroy();

    return;
}

static void case3(void)
{
    int i_ret = 0;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    
    frstat_ports_init(100);
    
    i_ret = frstat_ports_add_stat(ui_sip, ui_dip, us_dport, 1, 1, 1, 1);
    
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    
    frstat_ports_destroy();

    return;
}

int add_suite_frstat_ports_add_stat(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("framework frstat_ports_add_stat()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL ||
        CU_add_test(pSuite, "case3", case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
